package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {

    private StudentDao studentDao = new StudentDao();

    public boolean addStudent(Student stu) {

        return studentDao.addStudent(stu);

    }

    public boolean isExist(String id) {
        Student[] stus = studentDao.getAllStudent();

        boolean exists = false;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && id.equals(stus[i].getId())) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public Student[] getAllStudent() {
        Student[] allStudent = studentDao.getAllStudent();

        boolean flag = false;

        for (int i = 0; i < allStudent.length; i++) {
            if (allStudent[i] != null) {
                flag = true;
                break;
            }

        }
        if (flag) {
            return allStudent;
        } else {
            return null;
        }

    }

    public void delStudent(String id) {
        studentDao.delStudent(id);
    }

    public void updateStudent(String id, Student stu) {
        studentDao.updateStudent(id, stu);
    }
}
